<template>
  <v-data-table :headers="headers" :items="desserts" sort-by="calories" class="elevation-1">
    <template v-slot:top>
      <v-toolbar flat>
        <v-toolbar-title>内部户</v-toolbar-title>
        <v-divider class="mx-4" inset vertical></v-divider>
        <v-spacer></v-spacer>
        <v-dialog v-model="dialog" max-width="800px">
          <template v-slot:activator="{ on }">
            <v-btn color="primary" dark class="mb-2" v-on="on">新增内部户</v-btn>
          </template>
          <v-card>
            <v-card-title>
              <span class="headline">{{ formTitle }}</span>
            </v-card-title>

            <v-card-text>
              <v-container>
                <v-row>
                  <v-col cols="12" sm="6" md="4">
                    <v-text-field v-model="editedItem.subbnkn" label="法人行号"></v-text-field>
                  </v-col>



                  <v-col cols="12" sm="6" md="4">
                    <v-text-field v-model="editedItem.brc" label="机构编号"></v-text-field>
                  </v-col>

                  <v-col cols="12" sm="6" md="4">
                    <v-text-field v-model="editedItem.busnoa" label="业务代号"></v-text-field>
                  </v-col>
        
                  <v-col cols="12" sm="6" md="4">
                      <v-select 
                      :items="CurrNoItems" 
                      label="币种" 
                      v-model="editedItem.ccy"
                      item-text="name"
                      item-value="attributes"
                     ></v-select>
                  </v-col>

                    <v-col cols="12" sm="6" md="4">
                    <v-text-field v-model="editedItem.accno" label="账号"></v-text-field>
                  </v-col>
                    <v-col cols="12" sm="6" md="4">
                    <v-text-field v-model="editedItem.sernob" label="内部账顺序号"></v-text-field>
                  </v-col>
                    <v-col cols="12" sm="6" md="4">
                    <v-text-field v-model="editedItem.flgsiso" label="表内或表外标志"></v-text-field>
                  </v-col>

                    <v-col cols="12" sm="6" md="4">
                      <v-select 
                      :items="whetherItems" 
                      label="是否为标准户" 
                      v-model="editedItem.isflgst"
                      item-text="name"
                      item-value="attributes"
                     ></v-select>
                  </v-col>

                   <v-col cols="12" sm="6" md="4">
                      <v-select 
                      :items="whetherItems" 
                      label="是否头寸账户" 
                      v-model="editedItem.iscashac"
                      item-text="name"
                      item-value="attributes"
                     ></v-select>
                  </v-col>

                   <v-col cols="12" sm="6" md="4">
                    <v-text-field v-model="editedItem.balcur" label="当前余额"></v-text-field>
                  </v-col>
                   <v-col cols="12" sm="6" md="4">
                    <v-text-field v-model="editedItem.bald" label="余额方向"></v-text-field>
                  </v-col>
                   <v-col cols="12" sm="6" md="4">
                    <v-text-field v-model="editedItem.typubal" label="余额修改方式"></v-text-field>
                  </v-col>
                   <v-col cols="12" sm="6" md="4">
                    <v-text-field v-model="editedItem.amtmin" label="最低金额"></v-text-field>
                  </v-col>
                  <v-col cols="12" sm="6" md="4">
                    <v-text-field v-model="editedItem.amtcldr" label="发生额控制方向"></v-text-field>
                  </v-col>
                  <v-col cols="12" sm="6" md="4">
                    <v-text-field v-model="editedItem.balctrl" label="余额控制方向"></v-text-field>
                  </v-col>
            
                <v-col cols="12" sm="6" md="4">
                      <v-select 
                      :items="whetherItems" 
                      label="是否允许透支" 
                      v-model="editedItem.isovd"
                      item-text="name"
                      item-value="attributes"
                     ></v-select>
                  </v-col>
                  
                  <v-col cols="12" sm="6" md="4">
                    <v-text-field v-model="editedItem.amtlmto" label="透支限额"></v-text-field>
                  </v-col>
                  <v-col cols="12" sm="6" md="4">
                    <v-text-field v-model="editedItem.intflgb" label="计息标志"></v-text-field>
                  </v-col>
                  <v-col cols="12" sm="6" md="4">
                    <v-text-field v-model="editedItem.flgrpc" label="收付现标志"></v-text-field>
                  </v-col>
                  <v-col cols="12" sm="6" md="4">
                    <v-text-field v-model="editedItem.flglist" label="汇总入明细标志"></v-text-field>
                  </v-col>
                    <v-col cols="12" sm="6" md="4">
                    <v-text-field v-model="editedItem.typctl" label="控制方式"></v-text-field>
                  </v-col>
                  <v-col cols="12" sm="6" md="4">
                    <v-text-field v-model="editedItem.balfry" label="余额频度检查"></v-text-field>
                  </v-col>
                  <v-col cols="12" sm="6" md="4">
                    <v-text-field v-model="editedItem.brcbld" label="开户机构"></v-text-field>
                  </v-col>
                  <v-col cols="12" sm="6" md="4">
                    <v-text-field v-model="editedItem.datebld" label="开户日期"></v-text-field>
                  </v-col>
                  <v-col cols="12" sm="6" md="4">
                    <v-text-field v-model="editedItem.intflgb" label="计息标志"></v-text-field>
                  </v-col>
                  <v-col cols="12" sm="6" md="4">
                    <v-text-field v-model="editedItem.brcprf" label="核算机构"></v-text-field>
                  </v-col>
                  <v-col cols="12" sm="6" md="4">
                    <v-text-field v-model="editedItem.stsacc" label="账户状态"></v-text-field>
                  </v-col>

                </v-row>
              </v-container>
            </v-card-text>

            <v-card-actions>
              <v-spacer></v-spacer>
              <v-btn color="blue darken-1" text @click="close">取消</v-btn>
              <v-btn color="blue darken-1" text @click="save">保存</v-btn>
            </v-card-actions>
          </v-card>
        </v-dialog>
      </v-toolbar>
    </template>
    <template v-slot:item.actions="{ item }">
      <v-icon small class="mr-2" @click="editItem(item)">mdi-pencil</v-icon>
      <v-icon small @click="deleteItem(item)">mdi-delete</v-icon>
    </template>
    <template v-slot:no-data>
      <v-btn color="primary" @click="initialize">Reset</v-btn>
    </template>
  </v-data-table>
</template>

<script>
export default {
  data: () => ({
    thisSerseqn:'',
    chnelnoItems:[],
    whetherItems:[],
    CurrNoItems:[],
    dialog: false,
    brcItems:[],
    headers: [
      {
        text: "法人行号",
        align: "start",
        value: "subbnkn"
        ,width:150
      },
      { text: "机构编号", value:         "brc"     ,width:150 },
      { text: "业务代号", value:         "busnoa"  ,width:150 },
      { text: "币种", value:   	      "ccy"       ,width:150 },
      { text: "内部账顺序号", value:     "sernob"  ,width:150 },
      { text: "账号", value:             "accno"   ,width:150 },
      { text: "表内或表外标志", value:   "flgsiso" ,width:150 },
      { text: "是否为标准户", value:     "isflgst" ,width:150 },
      { text: "是否头寸账户", value:     "iscashac",width:150 },
      { text: "当前余额", value:         "balcur"  ,width:150 },
      { text: "余额方向", value:        "bald"     ,width:150 },
      { text: "余额修改方式", value:     "typubal" ,width:150 },
      { text: "最低金额", value:         "amtmin"  ,width:150 },
      { text: "最高金额", value:        "amtmax"   ,width:150 },
      { text: "发生额控制方向", value:   "amtcldr" ,width:150 },
      { text: "余额控制方向", value:     "balctrl" ,width:150 },
      { text: "是否允许透支", value:     "isovd"   ,width:150 },
      { text: "透支限额", value:         "amtlmto" ,width:150 },
      { text: "计息标志", value:        "intflgb"  ,width:150 },
      { text: "收付现标志", value:      "flgrpc"   ,width:150 },
      { text: "汇总入明细标志", value:   "flglist" ,width:150 },
      { text: "余额频度检查", value:     "balfry"  ,width:150 },
      { text: "开户机构", value:         "brcbld"  ,width:150 },
      { text: "开户日期", value:        "datebld"  ,width:150 },
      { text: "核算机构", value:         "brcprf"  ,width:150 },
      { text: "账户状态", value:         "stsacc"  ,width:150 },
      { text: "操作", value: "actions", sortable: false ,width:150 }
    ],
    desserts: [],
    editedIndex: -1,
    editedItem: {
      subbnkn: "",
      brc:"",
      busnoa:"",
      ccy:"",
      accno:"",
      balcur: "",
      bald:"",
      brcbld: "",
      brcprf: "",
    
    },
    defaultItem: {
      subbnkn: "",
      brc:"",
      busnoa:"",
      ccy:"",
      accno:"",
      balcur: "",
      bald:"",
      brcbld: "",
      brcprf: "",
    }
  }),

  computed: {
    formTitle() {
      return this.editedIndex === -1 ? "新增" : "修改";
    }
  },

  watch: {
    dialog(val) {
      val || this.close();
    }
  },

  created() {
    this.initialize();
    this.getDict();
  },

  methods: {
    initialize() {
     this.axios
        .get("/iaaccinfo/list")
        .then(response => {
          this.desserts = response.data.data;
        })
        .catch(response => {
          console.log(response.data.message);
        });
    },
     getDict(){
        this.axios
        .get("/dict/topName/渠道")
        .then(response => {
          this.chnelnoItems = response.data.data;
        })
        .catch(response => {
          console.log(response.data.message);
        });
        this.axios
        .get("/dict/topName/是否")
        .then(response => {
          this.whetherItems = response.data.data;
        })
        .catch(response => {
          console.log(response.data.message);
        });
        this.axios
        .get("/dict/topName/币种")
        .then(response => {
          this.CurrNoItems = response.data.data;
        })
        .catch(response => {
          console.log(response.data.message);
        });

        this.axios
        .get("/iaaccinfo/list")
        .then(response => {
          this.brcItems = response.data.data;
        })
        .catch(response => {
          console.log(response.data.message);
        });
      
      
        
    },
    editItem(item) {
      this.editedIndex = this.desserts.indexOf(item);
      this.editedItem = Object.assign({}, item);
      this.dialog = true;
    },

    

    deleteItem(item) {
      const index = this.desserts.indexOf(item);
      confirm("确定要删除此条记录吗?") &&
        this.axios.delete('/iaaccinfo/'+item.id)
          .then(res=>{
            this.desserts.splice(index, 1); 
          })
        
    },

    close() {
      this.dialog = false;
      this.$nextTick(() => {
        this.editedItem = Object.assign({}, this.defaultItem);
        this.editedIndex = -1;
      });
    },

    save() {
       this.axios.post("/iaaccinfo", this.$qs.stringify(this.editedItem)).then(res => {
          this.initialize();
          this.close();
      });
      
    }
  }
};
</script>